package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.business.domain.CcPurchaseInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.business.domain.CcPurchaseInfoSp;
import com.lxmes.business.service.ICcPurchaseInfoSpService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 采购审批单Controller
 * 
 * @author zhangzhiyu
 * @date 2023-06-28
 */
@Api(tags = "采购审批单")    
@RestController
@RequestMapping("/business/purchaseInfoSp")
public class CcPurchaseInfoSpController extends BaseController
{
    @Autowired
    private ICcPurchaseInfoSpService ccPurchaseInfoSpService;

    /**
     * 查询采购审批单列表
     */
    @ApiOperation("查询采购审批单列表")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        startPage();
        List<CcPurchaseInfoSp> list = ccPurchaseInfoSpService.selectCcPurchaseInfoSpList(ccPurchaseInfoSp);
        return getDataTable(list);
    }
    @GetMapping("/selectList")
    public TableDataInfo selectList(CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        startPage();
        List<CcPurchaseInfoSp> list = ccPurchaseInfoSpService.selectCcPurchaseInfoSpSelectList(ccPurchaseInfoSp);
        return getDataTable(list);
    }
    //订单入库数据
    @GetMapping("/rkList")
    public TableDataInfo rkList(CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        startPage();
        List<CcPurchaseInfoSp> list = ccPurchaseInfoSpService.selectCcPurchaseInfoSpRk(ccPurchaseInfoSp);
        return getDataTable(list);
    }



    /**
     * 导出采购审批单列表
     */
    @ApiOperation("导出采购审批单列表")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:export')")
    @Log(title = "采购审批单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        List<CcPurchaseInfoSp> list = ccPurchaseInfoSpService.selectCcPurchaseInfoSpList(ccPurchaseInfoSp);
        ExcelUtil<CcPurchaseInfoSp> util = new ExcelUtil<CcPurchaseInfoSp>(CcPurchaseInfoSp.class);
        util.exportExcel(response, list, "采购审批单数据");
    }

    /**
     * 获取采购审批单详细信息
     */
    @ApiOperation("获取采购审批单详细信息")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccPurchaseInfoSpService.selectCcPurchaseInfoSpById(id));
    }

    /**
     * 新增采购审批单
     */
    @ApiOperation("新增采购审批单")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:add')")
    @Log(title = "采购审批单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        return toAjax(ccPurchaseInfoSpService.insertCcPurchaseInfoSp(ccPurchaseInfoSp));
    }

    /**
     * 修改采购审批单
     */
    @ApiOperation("修改采购审批单")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:edit')")
    @Log(title = "采购审批单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcPurchaseInfoSp ccPurchaseInfoSp)
    {
        return toAjax(ccPurchaseInfoSpService.updateCcPurchaseInfoSp(ccPurchaseInfoSp));
    }

    /**
     * 删除采购审批单
     */
    @ApiOperation("删除采购审批单")
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:remove')")
    @Log(title = "采购审批单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccPurchaseInfoSpService.deleteCcPurchaseInfoSpByIds(ids));
    }
    /**
     * 导入采购审批单
     */
    @Log(title = "采购审批单", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<CcPurchaseInfoSp> util = new ExcelUtil<>(CcPurchaseInfoSp.class);
        List<CcPurchaseInfoSp> ccPurchaseInfoSpList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ccPurchaseInfoSpService.imporIteminfo(ccPurchaseInfoSpList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<CcPurchaseInfoSp> util = new ExcelUtil<>(CcPurchaseInfoSp.class);
        util.importTemplateExcel(response,"采购审批单");
    }
    /**
     * 采购单生成合同
     */
    @PreAuthorize("@ss.hasPermi('business:purchaseInfoSp:htsc')")
    @Log(title = "采购单生成合同", businessType = BusinessType.UPDATE)
    @GetMapping("/htsc/{id}")
    public AjaxResult htsc(@PathVariable("id")Long[] ids)
    {
        return toAjax(ccPurchaseInfoSpService.htsc(ids));
    }
}
